<?


function trans_excel_to_array($array){


//导入PHPExcel必须的问题
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/Writer/Excel2007.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/Writer/Excel5.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/IOFactory.php';




//传递的时候，填写文件的完整地址
$name=$array['filename'];
$path=$array['path'];
$format=$array['format'];



date_default_timezone_set('Europe/London'); //设置时间



$inputFileName =$path."/".$name;




//判断一下，文件是2007还是旧版的excel
if(strstr($name,".")==".xls")
{
    $inputFileType = 'Excel5';
}
else if(strstr($name,".")==".xlsx")
{
    $inputFileType = 'Excel2007';
}
else
{
    echo "文件格式异常。请上传Microsoft Excel 文件";
}



//echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
/*
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); //取得总行数
$highestColumn = $sheet->getHighestColumn(); //取得总列
*/
$objWorksheet = $objPHPExcel->getActiveSheet();//取得总行数
$highestRow = $objWorksheet->getHighestRow();//取得总列数
//echo 'highestRow='.$highestRow;


//echo "<br>";
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
//echo 'highestColumnIndex='.$highestColumnIndex;
//echo "<br />";



$headtitle=array();
$result=array();




for ($row = 0;$row <= $highestRow;$row++)
{
    $strs=array();
    //注意highestColumnIndex的列数索引从0开始
    for ($col = 0;$col < $highestColumnIndex;$col++)
    {
        $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();

//富文本转换字符串
        if(($strs[$col] instanceof PHPExcel_RichText)&&($format))
        {
            $strs[$col] = $strs[$col]->__toString();
        }




        $result[$row][$col]=$strs[$col];
    }


}












        return $result;


}





?>